package edu.purdue.cs.ds.vss;

import java.math.BigInteger;
import java.util.ArrayList;


public class Verifier {

	public boolean verifyVec(VerifiableSharing vs) {
		ArrayList<BigInteger> aList = vs.getA();
		int size = aList.size();
		BigInteger val = null;
		for(int i = 1; i < size; i++) {
			if(val == null) {
				val = aList.get(i);
			} else {
				val = val.multiply(aList.get(i)).mod(Constants.p);
			}
		}
		
		return aList.get(0).equals(val);
	}
	
	public boolean verifyVecStandAlone(ArrayList<BigInteger> aList){
		
		int size = aList.size();
		BigInteger val = null;
		for(int i = 1; i < size; i++) {
			if(val == null) {
				val = aList.get(i);
			} else {
				val = val.multiply(aList.get(i)).mod(Constants.p);
			}
		}
		
		return aList.get(0).equals(val);
	}

	public boolean verifyShare(ArrayList<BigInteger> aList, int i, BigInteger si, BigInteger ri) {
		BigInteger c = aList.get(i);
		
		return c.equals(Generator.pedersenCommit(si, ri));
	}
	
	public boolean verifyShareClass(VerifiableShare vs){
		
		Share tmp = vs.getShare();
		BigInteger c = tmp.getLambda().get(tmp.getIndex()+1);
		BigInteger s = tmp.getS();
		BigInteger r = tmp.getR();
		return c.equals(Generator.pedersenCommit(s,r));
	}
}
